<#import "/magicsoft/macro/standardLib.ftl" as std />

<#macro login title userEntitySymbol indexPage buttons script extraCss extraStyle header footer icon extendedHtml extendedLoginForm extendedDoLogin body showLocale=false>

<#global defaultLabelWidth=90 />

<#assign defaultButtons>
<div class="col-md-offset-16 col-md-10">
	<a href="#" id="_btnLogin" class="linkbutton"><i class="fa fa-sign-in"></i> ${model.getBundleString('jersey','login.button.login')}</a>
</div>
</#assign>

<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
        <meta name="apple-mobile-web-app-capable" content="yes" />
		<#if icon??><link rel="shortcut icon" href="${icon}" /></#if>
		<title>${title}</title>
		<#include "/magicsoft/macro/includeStylesheet.ftl" />
		${extraCss}
		<style>
		.login-panel .panel-title {
			margin: 10px 10px 0px 10px;
		}
		.login-panel .panel-icon.fa {
			margin-top: -6px !important;
		}
		.login-panel .panel-header {
			border-bottom: 0px;
		}
		${extraStyle}
		</style>
	</head>
	
	<#if model.softdogEnable>
	<object id="AuthIE" name="AuthIE" width="0px" height="0px"
		codebase="DogAuth.CAB#version=2,3,1,58083"
		classid="CLSID:05C384B0-F45D-46DB-9055-C72DC76176E3">
	</object>
	</#if>
	<body <#if !body??>class="easyui-layout"</#if> fit="true" >
		<#include "/magicsoft/macro/includeJavascript.ftl" />
		<#if model.softdogEnable>
		<script type="text/javascript" src="${model.contextPath}/magicsoft/softdog/softdog.js"></script>
		</#if>
		${extendedHtml}
		<script>
		<#if !extendedDoLogin??>
		function _doLogin() {
			$('#_loginForm').form('submit', {
				url: '${model.basePath}/magicsoft/common/accountcenter/login',
				success: function(response) {
					if (response == '') {
						window.location.href = '${indexPage}';
					} else {
						var result = JSON.parse(response);
						if (result.responseText.indexOf('SOFTDOG_VALIDATE_ERROR') >= 0) {
							var pwdSurplusNumber = result.responseText.split(':');
							_softdogReportStatus(parseInt(pwdSurplusNumber[1]));
						} else {
							magicsoft.requestErrorHandler(JSON.parse(response));
						}
					}
				}
			});
		}
		</#if>
		${extendedDoLogin}
		$.parser.onComplete = function() {
			<#if model.params.showExpireMsg??>
			magicsoft.showError("${model.getBundleString('jersey','login.message.showexpiremsg')}");
			</#if>
			$('#_txtAccount').standardInputAPI('focus');
			$('#_txtAccount').standardInputAPI('onKeydown', function(e) {
				if (e.keyCode == "13") {
					$('#_txtPassword').standardInputAPI('focus');
				}
			});
			$('#_txtPassword').standardInputAPI('onKeydown', function(e) {
				if (e.keyCode == "13") {
				$('#_btnLogin').click();
				}
			});
			$('#_selectlocale').standardSelectAPI('onChange',function(){
				window.location.href=window.location.pathname+'?localeIndex='+$('#_selectlocale').standardSelectAPI('getValue')
			})
			$('#_btnLogin').on('click', function() {
				if (typeof _softdogValidator != 'undefined') {
					_softdogValidator(1);
				} else {
					_doLogin();
				}
				return false;
			});
			
			${script}
			$.parser.onComplete = magicsoft.emptyFn;
		}
		</script>	
		
		<#--#login_box_div #login_box_panel #login_box_panel_panel extendStyle供登录界面扩展使用-->
		<#if !body??>
		<div data-options="region:'north',split:false,collapsible:false,border:false,height:134" class="login-bg-top">
			${header}
		</div>
		<div data-options="region:'center',split:false,collapsible:false,border:false" id="login_body">
			<div style="position:absolute;left:30%;top:30%;" id="login_box_div">
				<div class="login-panel" id="login_box_panel">
					<div class="easyui-panel" title="" style="width:400px;" data-options="iconCls:'fa fa-key'" id="login_box_panel_panel">
					    <div class="container-fluid">
							<form id="_loginForm" method="POST" class="form-horizontal edit-form">
								<#if !(extendedLoginForm??)>
									<div class="row">
										<@std.text id="_txtAccount" name="account" label="${model.getBundleString('jersey','login.account')}" />
									</div>
									<div class="row">
										<@std.text id="_txtPassword" name="password" inputType="password" label="${model.getBundleString('jersey','login.password')}" />
									</div>
								</#if>
								${extendedLoginForm}
								<#if showLocale>
									<div class="row">
										 <#if model.localeId??>
											 <@std.select value="${model.localeId}" label="${model.getBundleString('jersey','login.locale')}" id="_selectlocale" name="locale" options=model.localeOptions/>
										 <#else>
										 	<@std.select value="${model.localeIndex}" label="${model.getBundleString('jersey','login.locale')}" id="_selectlocale" name="locale" options=model.localeOptions/>
										 </#if>
									</div>
								</#if>
								<#if model.autoLoginEnable>
									<div class="row" style="margin-bottom:0px">
										<@std.checkbox name="autoLoginNextTime" label="${model.getBundleString('jersey','login.autologinnexttime')}" />
									</div>
								</#if>
								<div class="row" style="margin-bottom:0px">
									${buttons!defaultButtons}
								</div>
								<input type="hidden" name="userEntitySymbol" value="${userEntitySymbol}" />
								<input type="hidden" id="_softdogAuthCode" name="softdogAuthCode" value="${model.softdogAuthcode}" />
								<input type="hidden" id="_softdogChallenge" name="softdogChallenge" value="${model.softdogChallenge}" />
								<input type="hidden" id="_softdogId" name="softdogId" />
								<input type="hidden" id="_softdogDigest" name="softdogDigest" />
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="login-bg-bottom" style="height:50px" data-options="region:'south',split:false,collapsible:false,border:false" >
			${footer}
		</div>
		</#if>
	</body>
	${body}
</html>
</#macro>